package com.wgl.order.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wgl.model.order.OrderInfo;
import com.wgl.model.vo.order.OrderCountQueryVo;
import com.wgl.model.vo.order.OrderQueryVo;
import com.wgl.order.service.OrderService;
import com.wgl.yygh.result.Result;
import com.wgl.yygh.util.AuthContextHolder;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author wgl
 * @version 1.0.0
 * @ClassName OrderApi.java
 * @Description TODO
 * @createTime 2022年02月13日 18:19:00
 */
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderApi {
    @Resource
    private OrderService orderService;

    /**
    * @Author: Wgl
    * @Description: 生成订单
    * @Date: 2022/2/13 18:27;
    * @param scheduleId:
     * @param patientId: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @PostMapping("/auth/submitOrder/{scheduleId}/{patientId}")
    public Result saveOrder(@PathVariable String scheduleId,@PathVariable Long patientId){
        Long orderId = orderService.saveOrder(scheduleId,patientId);

        return Result.ok(orderId);
    }

    @GetMapping("/auth/getOrders/{orderId}")
    public Result getOrders(@PathVariable String orderId){
        return Result.ok(orderService.getOrder(orderId));
    }
    //订单列表（条件查询带分页）
    @GetMapping("auth/{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       OrderQueryVo orderQueryVo, HttpServletRequest request) {
        //设置当前用户id
        orderQueryVo.setUserId(AuthContextHolder.getUserId(request));
        Page<OrderInfo> pageParam = new Page<>(page,limit);
        IPage<OrderInfo> pageModel =
                orderService.selectPage(pageParam,orderQueryVo);
        return Result.ok(pageModel);
    }

    @GetMapping("/auth/cancelOrder/{orderId}")
    public Result cancelOrder(@PathVariable Long orderId){
        Boolean isOrder = orderService.cancelOrder(orderId);
        return Result.ok(isOrder);
    }

    /**
    * @Author: Wgl
    * @Description: 获取订单统计数据
    * @Date: 2022/2/16 15:43;
    * @param orderCountQueryVo: ;
    * @return: java.util.Map<java.lang.String,java.lang.Object>;
    */
    //
    @PostMapping("/inner/getCountMap")
    public Map<String, Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo) {
        return orderService.getCountMap(orderCountQueryVo);
    }
}
